const noop = () => {
};

/* eslint-disable */
module.exports = function (redisClient, module) {
    function sortedSetAddMulti(key, scores, values, callback) {
        if (!scores.length || !values.length) {
            return callback();
        }
        if (scores.length !== values.length) {
            return callback(new Error('[[error:invalid-data]]'));
        }
        const args = [key];

        for (let i = 0; i < scores.length; i += 1) {
            args.push(scores[i], values[i]);
        }
        redisClient.zadd(args, callback);
    }

    module.sortedSetAdd = function (key, score, value, callback = noop) {
        if (!key) {
            return setImmediate(callback);
        }
        if (Array.isArray(score) && Array.isArray(value)) {
            return sortedSetAddMulti(key, score, value, callback);
        }
        redisClient.zadd(key, score, value, callback);
    };


    module.sortedSetsAdd = function (keys, score, value, callback = noop) {
        if (!Array.isArray(keys) || !keys.length) {
            return callback();
        }
        const multi = redisClient.multi();

        for (let i = 0; i < keys.length; i += 1) {
            if (keys[i]) {
                multi.zadd(keys[i], score, value);
            }
        }
        multi.exec(callback);
    };
};
/* eslint-enable */
